﻿
    using System;
    using System.IO.IsolatedStorage;
namespace WCYCReader.Utility
{
    public class StorageFileHelper
    {
        private static IsolatedStorageFile _StorageFile = IsolatedStorageFile.GetUserStoreForApplication();

        public StorageFileHelper(string createDir)
        {
            if (!this.StorageFile.DirectoryExists(createDir))
            {
                this.StorageFile.CreateDirectory(createDir);
            }
        }

        private string CheckDirPath(string n_FilePath)
        {
            string str = null;
            string str2 = @"\";
            if (n_FilePath.Length <= 0)
            {
                return str;
            }
            int length = n_FilePath.LastIndexOf(str2);
            if (length != -1)
            {
                return n_FilePath.Substring(0, length);
            }
            return n_FilePath;
        }

        public void CopyPicFileToStorage(string n_DestinationFileName, int n_PicWidht, int n_PicHeight)
        {
            string destinationFileName = string.Empty;
            string sourceFileName = this.GetTempDir() + "Avatar.jpg";
            destinationFileName = this.GetPictureDir(n_PicWidht, n_PicHeight) + n_DestinationFileName + ".jpg";
            _StorageFile.CopyFile(sourceFileName, destinationFileName);
        }

        public void CreateDir(string n_DirPath)
        {
            string str = this.CheckDirPath(n_DirPath);
            if ((str.Length > 0) && !this.IsDirectoryExists(str))
            {
                _StorageFile.CreateDirectory(str);
            }
        }

        public void CreateFile(string n_FileName)
        {
            this.CreateDir(n_FileName);
            if (!this.IsFileExists(n_FileName))
            {
                _StorageFile.CreateFile(n_FileName);
            }
        }

        public void DeleteFile(string n_FileName)
        {
            if (this.IsFileExists(n_FileName))
            {
                _StorageFile.DeleteFile(n_FileName);
            }
        }

        public void DelteleDir(string n_DirPath)
        {
            if (this.IsDirectoryExists(n_DirPath))
            {
                _StorageFile.DeleteDirectory(n_DirPath);
            }
        }

        public string GetAppDir()
        {
            return @"\";
        }

        public string GetBKPictureDir()
        {
            return (this.GetAppDir() + @"BKImage\");
        }

        public string GetPictureDir(int n_ImageWidth, int n_ImageHeight)
        {
            return string.Concat(new object[] { this.GetAppDir(), "Image", n_ImageWidth, "X", n_ImageHeight, @"\" });
        }

        public string GetTempDir()
        {
            return (this.GetAppDir() + @"Temp\");
        }

        public bool IsDirectoryExists(string n_DirPath)
        {
            if (n_DirPath.Length <= 0)
            {
                return false;
            }
            return _StorageFile.DirectoryExists(n_DirPath);
        }

        public bool IsFile(string fileName)
        {
            return this.StorageFile.FileExists(fileName);
        }

        public bool IsFileExists(string n_DirPath)
        {
            if (n_DirPath.Length <= 0)
            {
                return false;
            }
            return _StorageFile.FileExists(n_DirPath);
        }

        public IsolatedStorageFile StorageFile
        {
            get
            {
                return _StorageFile;
            }
        }
    }
}

